<!--
* description: 变更网点（含输入框，多选）
* author: dxuem
* createdDate: 2019-10-09
-->
<template>
 
    <el-col :span="span">
      <lableName  :style="span==12?'width:14%':''"   :validrule="validrule"       :curLabelName="curLabelName" :isShowLabel="isShowLabel" :isRequire="isRequire"></lableName>
      <el-input
        :style="setInputWidth(span)"
        placeholder="请选择"
        v-model="modelText"
        :disabled="disabled"
        size="small"
        suffix-icon="el-icon-menu"
        @clear="clearCode"
        clearable
        @blur="sendCode"
        @focus="getFocusCode"
      ></el-input>
      <validateFormate :curLabelName="curLabelName"></validateFormate>
    
    <ChangeDlr
      ref="ChangeDlr"
      :popupsVisible="curPopupsVisible"
      :codeField="codeField"
      :textField="textField"
      :comType="comType"
      :valueObject="curValueObject"
      :popupsKey="popupsKey"
      :code="modelCode"
      :text="modelText"
      :key="curPopupsKey"
      :isMul="isMul"
      @changeCode="getComponentCode1"
    ></ChangeDlr>
</el-col>
</template>
<script>
import { searchInputMixins } from "@/components/mixins/searchInputMixins";
import { valueObjectMixins } from "@/components/mixins/valueObjectMixins";
// import lableName from "@/components/lableName";
import ChangeDlr from "@/components/crm/crmEjectWindows/crmAllDlr/edit";
// import validateFormate from "@/components/validateFormate";
export default {
  // 组件混入对象
  mixins: [searchInputMixins, valueObjectMixins],
  components: {
    ChangeDlr,
    lableName: () => import("@/components/lableName"), //标题溢出样式组件
    validateFormate: () => import("@/components/validateFormate"), //校验提示样式组件
  },
  props: {
    emitCode: {
      type: Function,
      default: function() {
        return "";
      }
    }
  },
  data() {
    return {
      curLabelName: this.labelName === "" ? "变更网点" : this.labelName,
      row: {}
    };
  },
  methods: {
    // 重写显示时执行事件
    onShow() {
      var parent = this.$utils.getHasFormFieldParentComponent(this);
      if (
        parent.formField &&
        parent.formField.carBrandCode &&
        parent.formField.carBrandCode !== ""
      ) {
        //赋值
        this.curValueObject.carBrandCode = parent.formField.carBrandCode;
        this.curPopupsKey = this.codeField + this.$utils.generateId();
      } else {
        // this.$alert('请先选择品牌', '提示', {
        //   confirmButtonText: '确定',
        //   callback: action => {
        //     this.close()
        //   }
        // })
      }
    },
    getComponentCode1(
      code,
      text,
      codeField,
      comType,
      popupsKey,
      textField,
      otherField,
      selectData
    ) {
      this.getComponentCode(
        code,
        text,
        codeField,
        comType,
        popupsKey,
        textField,
        otherField,
        selectData
      );
      var parent = this.$utils.getHasFormFieldParentComponent(this);
      let results = selectData[0];
      this.row = selectData;
      for (let key in parent.formField) {
        if (results.hasOwnProperty(key)) {
          parent.formField[key] = results[key];
        }
      }
      if(parent.formField[this.codeField]=="")
      {
        parent.formField[this.codeField]=results.dlrCode
      }
      this.$emit("emitCode", selectData);
    },
    setInputWidth(span) {
      switch (span) {
        case 6:
          return "";
        case 12:
          return "width:85%;line-height: 38px;";
      }
    },
    // 清空输入输入框，清空整行数据
    clearCode() {
      let results=this.row[0]
      for (let key in results) {
        results[key] = "";
      }
      var parent = this.$utils.getHasFormFieldParentComponent(this);
      for (let key in parent.formField) {
        if (results.hasOwnProperty(key)) {
          parent.formField[key] = results[key];
        }
      }
      this.$emit("emitCode", this.row);
    }
  }
};
</script>